export default {
  namespaced: true,

  state: {
    user: {},
  },
  mutations: {
    SET_USER(state: { user: any; }, user: any) {
      state.user = user;
      window.localStorage.setItem('userInfo',user)
    },
    LOGOUT(state: { user: {}; }) {
      state.user = {};
    },
  },
  actions: {
    login({ commit }: any, userInfo: any) {
      // 模拟登录逻辑  
      setTimeout(() => {
        commit('SET_USER', { ...userInfo, id: 1, token: 'fake-jwt-token' });
      }, 1000);
    },
    logout({ commit }: any) {
      commit('LOGOUT');
    },
  },
  getters: {
    isLoggedIn: (state: { user: { token: any; }; }) => !!state.user.token,
    user: (state: { user: any; }) => state.user,
  },
};